﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using System.Text;

public partial class Task_UserReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        StringBuilder sb = new StringBuilder();
        TaskInfo task = Task.GetTask(int.Parse(Request.QueryString["TaskId"]));
        sb.Append("<div class=title>" + task.Title + "</div>");
        sb.Append("<div class=date>[" + task.StartDate.ToShortDateString() + "—" + task.EndDate.ToShortDateString() + "]</div>");
        if (task.Comment != "")
        {
            sb.Append("<div class=comment>" + UserFun.TextToHtml(task.Comment) + "</div>");
        }
        //显示附件
        if (task.Files.Count > 0)
        {
            foreach (TaskFileInfo file in task.Files)
            {
                sb.Append("<div class=file><img src=../images/attachment.gif alt=> <a href=../Upload" + file.FileName + " target=_blank>" + file.FileTitle + "</a></div>");
            }
        }
        Body.Text = sb.ToString();

        TaskLogInfo log = TaskLog.GetTaskLog(int.Parse(Request.QueryString["TaskId"]), Request.QueryString["UserId"]);
        if (log != null)
        {
            ProgressList.SelectedIndex = ProgressList.Items.IndexOf(ProgressList.Items.FindByValue(log.Progress.ToString("##")));
            Comment.Text = log.Comment;
        }

        if (task.Child > 0)
        {
            ProgressList.SelectedIndex = 0;
            ProgressList.Enabled = false;
        }
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        UserInfo user = Yipusoft.Account.BLL.User.GetUser(Context.User.Identity.Name);
        TaskLogInfo log = new TaskLogInfo();
        log.TaskId = int.Parse(Request.QueryString["TaskId"]);
        log.UserId = Request.QueryString["UserId"];
        log.Progress = decimal.Parse(ProgressList.SelectedValue);
        log.Comment = Comment.Text;
        log.CreateDepartment = Department.GetDepartment(user.DepartmentID).FullName;
        log.CreateUser = user.UserName;
        log.CreateDate = DateTime.Now;
        log.UpdateDepartment = Department.GetDepartment(user.DepartmentID).FullName;
        log.UpdateUser = user.UserName;
        log.UpdateDate = DateTime.Now;
        int logId = TaskLog.Insert(log);
        TaskUser.UpdateProgress(int.Parse(Request.QueryString["RootId"]), Request.QueryString["UserId"]);
        Response.Redirect("SaveReport.aspx?RootId=" + Request.QueryString["RootId"] + "&UserId=" + Request.QueryString["UserId"] + "&LogId=" + logId.ToString());
    }
    protected void ButtonCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("UserView.aspx?RootId=" + Request.QueryString["RootId"] + "&UserId=" + Request.QueryString["UserId"]);
    }
}
